function timeChange(time) {
		var d = new Date(time);
		return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
	}

function compareDate(inHouseDate, outHouseDate) {
		var d1 = new Date(inHouseDate);
		var d2 = new Date(outHouseDate);
		if (d2 >= d1) {
			return true;
		} else {
			return false;
		}
	}

function compareObjectDate() {
		return function(object1, object2) { // 属性值为数字  
            	var value1 = new Date(object1.outhouse_date);  
            	var value2 = new Date(object2.outhouse_date);  
            	return value1 - value2;  
        	} 
	}

function getBaseData(conn,sql){
		let pro = new Promise((resolve, reject) => {
			conn.query(sql, function(err, rows, fields) {
				if (err) throw err;
				else {
					resolve(rows);
				}
			});
		});
		return pro;
	}

function getMaxID(arr) {
		var max = 0;
		arr.forEach((value)=>{
	        if(value.id>max)
	        {
	        	max = value.id;
	        }
		});
		return max;
	}

function deepCopy(o) {
		var isArray = o instanceof Array;
		var isObject = o instanceof Object;
		if(!isObject) return o;
		var n = (isArray ? [] : {});
		for(var k in o) n[k] = deepCopy(o[k]);
		return n;
	}

function updateArrayData(sourceArr,distArr){
   		for(var i = 0;i < sourceArr.length;i ++) {
   	 		for(var j = 0;j < distArr.length;j ++) {
   	 			if(sourceArr[i].id == distArr[j].id) {
   	 				distArr[j] = sourceArr[i];
   	 				break;
   	 			}
   	 		}
   	 		if(j >= distArr.length){
   	 			distArr.push(sourceArr[i]);
   	 		}
   		}
	}

function partnerMatch(inList,outList){
		var inString = '';
		var outString = '';
		inList.sort();
		outList.sort();
		inList.forEach((e)=>{
			inString = inString + e;
		});
		outList.forEach((e)=>{
			outString = outString + e;
		});
		if(inString === outString){
			return true;
		}else{
			return false;
		}
	}

module.exports = {
	timeChange:timeChange,
	compareDate:compareDate,
	getBaseData:getBaseData,
	compareObjectDate:compareObjectDate,
	getMaxID:getMaxID,
	deepCopy:deepCopy,
	updateArrayData:updateArrayData,
	partnerMatch:partnerMatch
}
